package com.quwan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.app.vo.FollowOrderDTO;
import com.quwan.entity.TCollectOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author quan
 * @date 2021-12-19 15:30
 */


public interface TCollectOrderMapper extends BaseMapper<TCollectOrder> {
    @Insert("insert into t_collect_order(m_id,publish_order_id,status,un_lock)" +
            "values (#{mId} ,#{publishOrderId} ,#{status} ,#{unLock})" +
            "ON duplicate key update status =#{status} ")
    Integer findOrSetCollectOrder(TCollectOrder tCollectOrder);

    @Select("select " +
            "m.img_url,m.nick_name,o.id publish_order_id,o.other_desc content,o.price,o.unit ,o.m_id,o.category_id category " +
            "from t_publish_order o  left  join  t_member m on o.m_id = m.id " +
            "where exists(select 1 from t_collect_order  c where c.m_id = #{id} and c.publish_order_id = o.id and status =1) and o.status =1  ")
    Page<FollowOrderDTO> selectCollectOrderListByMId(Page<Object> objectPage, @Param("id") String id);

    @Select("select " +
            "m.img_url,m.nick_name,o.id publish_order_id,o.other_desc content,o.price,o.unit ,o.m_id,o.category_id category " +
            "from t_publish_order o  left  join  t_member m on o.m_id = m.id " +
            "where o.id in (${ids}) and o.status =1  ")
    List<FollowOrderDTO> selectAccessHistoryOrderListByIds( @Param("ids") String ids);
}